<!--_meta 作为公共模版分离出去-->
<#include "include/_meta.html">
<!--/meta 作为公共模版分离出去-->

<title>添加管理员 - 管理员管理</title>
<meta name="keywords" content="汽车租赁">
<meta name="description" content="H-ui.admin v2.3，是一款由国人开发的轻量级扁平化网站后台模板，完全免费开源的网站后台管理系统模版，适合中小型CMS后台系统。">
</head>
<body>
<article class="page-container">
	<form class="form form-horizontal" id="form-admin-add" >
<div width="900px">
	<div style="float:left;width:500px;height:400px;">
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>角色名称：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="text" class="input-text" value="${role.rolename}" placeholder="角色名称" 
				 style="width:300px;" id="rolename" name="rolename">
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>角色编码：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="text" style="width:300px;" class="input-text" autocomplete="off" value="${role.roleid}" placeholder="角色编码" readonly=true id="roleid" name="roleid">
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3">是否启用：</label>
			<div class="formControls col-xs-8 col-sm-9 skin-minimal">
				<div class="radio-box">
					<input name="isabled" type="radio" id="us_1" value="1" checked>
					<label for="sex-1">启用</label>
				</div>
				<div class="radio-box">
					<input type="radio" id="us_0" name="isabled" value="0">
					<label for="sex-2">禁用</label>
				</div>
			</div>		
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>添加时间：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="text" style="width:270px;" class="input-text" autocomplete="off" value="${role.addtime}" onClick="WdatePicker({dateFmt:'yyyy-MM-dd'})" placeholder="添加时间" id="addtime" name="addtime">
				
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3">角色描述：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<textarea id="decrib" style="width:300px;" name="decrib" cols="" rows="" class="textarea"  placeholder="说点什么...100个字符以内" dragonfly="true" onKeyUp="textarealength(this,100)"></textarea>
				<p class="textarea-numberbar" style="width:300px;"><em class="textarea-length">0</em>/100</p>
			</div>
		</div>
	</div>	
	<div style="float:right;width:300px">
		<div vlass="row cl">
			<label class="form-label col-xs-4 col-sm-6"><span class="c-red">*</span>选择权限资源：</label>
			<div class="formControls col-xs-8 col-sm-9" style="width:300px;">
				 <div id="rMenu" style="width:100%;height:100%;float:left;"   >
					<ul style="height:700px;" id="treeDemo" class="ztree">
					</ul>
				</div>
			</div>		
		</div>
	</div>
</div>
	<div class="row cl">
		<div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
			<input class="btn btn-primary radius" type="button" value="&nbsp;&nbsp;提交&nbsp;&nbsp;" onclick="fun_chb()"/>
	
		</div>
	</div>
</form>
</article>

<!--_footer 作为公共模版分离出去--> 
<#include "include/_footer.html">
<!--/_footer /作为公共模版分离出去--> 
<script type="text/javascript" src="lib/webuploader/0.1.5/webuploader.min.js"></script> 

<!--请在下方写此页面业务相关的脚本--> 
<script type="text/javascript">

	var zNodes;
	var setting = {
		view: {
		dblClickExpand: false,
		showLine: false,
		selectedMulti: false		
	},
	data: {
		simpleData: {
			enable:true,
			idKey: "id",
			pIdKey: "pId",
			rootPId: ""
		}
	},
	check:{			
		enable: true,
		chkStyle: "checkbox",		
		chkboxType: { "Y": "ps", "N": "ps" }
	},
	callback: {		
		onClick:zTreeOnCheck,		
		onRightClick: zTreeOnRightClick
	}
	};
	function zTreeOnCheck(event, treeId, treeNode) {		
    	var childNodes = zTree.transformToArray(treeNode);
    	
    	var perId = childNodes[0].id;  
    	var perType = childNodes[0].resType;
    	//alert("节点ID:"+perId);
    	//alert("父节点ID:"+perType);    	
    	if(perType==3 || perType==1 || perType==999){     		  		
    		return;
    	}
    	/*
    	var resourceIframe=window.parent.document.getElementById("resourceSelect");    	
    	var src = "/getResSelect?permisid="+perId;
    	resourceIframe.src=src;
    	resourceIframe.reload();
 		*/
}
var classpurview;
function fun_chb(){
	zTree = $.fn.zTree.getZTreeObj("treeDemo");
    checkCount = zTree.getCheckedNodes(true);
 
    classpurview = "";
    for(var i=0;i<checkCount.length;i++) {
    	classpurview += "," + checkCount[i].id
    }
    //alert(classpurview);
    $('#form-admin-add').submit();
    
}
function zTreeOnRightClick(event, treeId, treeNode) {
	 zTree.selectNode(treeNode);
	  var childNodes = zTree.transformToArray(treeNode); 
	 checkTreeId = childNodes[0].id;
	 
	 if(checkTreeId == "topDept"){
	    showRMenu("topDept", event.clientX, event.clientY);
	 }else{
	    showRMenu("node", event.clientX, event.clientY);
	 }
	 
}
function showRMenu(type, x, y) {
	 $("#rMenu ul").show();
	 if("topDept" == type){
	    $("#m_add").show();
	     $("#m_del").hide();
	 }else{
	   $("#m_add").show();
	   $("#m_del").show();
	 }
	 x=x-20;
	 y=y-5;
	 rMenu.css({"top":y+"px", "left":x+"px", "visibility":"visible"});
	 $("body").bind("mousedown", onBodyMouseDown);
}
function hideRMenu() {
	 if (rMenu) rMenu.css({"visibility": "hidden"});
	 $("body").unbind("mousedown", onBodyMouseDown);
}
function onBodyMouseDown(event){
 if (!(event.target.id == "rMenu" || $(event.target).parents("#rMenu").length>0)) {
	 rMenu.css({"visibility" : "hidden"});
 }
}
function resetTree() {
  hideRMenu();
  $.fn.zTree.init($("#treeDemo"), setting, zNodes);
}
var zTree, rMenu,checkTree;
$(function(){	
	$.ajax({	
     type: "get",    
      url:"/getResToJson",     
      dataType:"json",     
      async:false,   
      success:function(data){     
      	zNodes=data;
      }
	});
	
  $.fn.zTree.init($("#treeDemo"),setting,zNodes); 
  zTree = $.fn.zTree.getZTreeObj("treeDemo");
  rMenu = $("#rMenu");
  
	var uploader = WebUploader.create({
		auto: true,
		swf: 'lib/webuploader/0.1.5/Uploader.swf',
		server: '/uploadFile',
		pick: '#filePicker',
		fileVal:'uploadfile',
		resize: false,
		accept: {
			title: 'Images',
			extensions: 'gif,jpg,jpeg,bmp,png',
			mimeTypes: 'image/*'
		}
	});


	$('.skin-minimal input').iCheck({
		checkboxClass: 'icheckbox-blue',
		radioClass: 'iradio-blue',
		increaseArea: '20%'
	});
	
	$("#form-admin-add").validate({
		
		onkeyup:false,
		focusCleanup:true,
		success:"valid",
		submitHandler:function(form){
			
	   		$.ajax({
	            type: 'post', 
				contentType:"application/json", 
	            url: '/saveEditRoles?roleid='+$("#roleid").val()+'&checkAll='+classpurview, 
	            data:JSON.stringify({
						'rolename': $("#rolename").val()+'',
						'roleid': $("#roleid").val(),
						 'isabled':$("#isabled").val(),
						'addtime':$("#addtime").val(),
						'decrib': $("#decrib").val(),
						}),
	            success:function(data){ 
	 				console.log('提交成功！');
	 				var index = parent.layer.getFrameIndex(window.name);
					parent.$("#searchUsers").click();
					parent.layer.close(index);
	            }
	
	        });

			
		}
	});

});

</script> 
<!--/请在上方写此页面业务相关的脚本-->
</body>
</html>